package com.lxz.jucdemo.volatile_demo;

import java.util.concurrent.TimeUnit;

/**
 * @Author: 刘新智
 * @Date: 2025/10/27 18:33
 * @Description:  volatile关键字
 * @Version: v1.0
 */
public class VolatileTest {
    private static volatile int number = 0;
    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            while(number==0){
                System.out.println("a");
            }
        }).start();

        TimeUnit.SECONDS.sleep(1);

        number=1;
        System.out.println(number);
    }
}

